import request from '@/utils/http'

// 商品列表数据
export const getCartListAPI = (queryInfo) => {
    return request({
        method: 'GET',
        url: 'goods',
        params: queryInfo
    })
}

// 删除商品
export const delCartAPI = (id) => {
    return request({
        method: 'DELETE',
        url: `goods/${id}`
    })
}

// 修改商品
export const editCartAPI = (id,editForm) => {
    return request({
        method:'PUT',
        url:`goods/${id}`,
        data:editForm
    })    
}

// 添加商品
export const addCartAPI = (data) =>{
    return request({
        method:'POST',
        url:'goods',
        data
    })
}

// 商品分类列表
export const getCategoriesListAPI = (query) => {
    return request({
        method: 'GET',
        url: 'categories',
        params: query
    })
}

// 添加商品分类
export const addCategoriesAPI = (data) => {
    return request({
        method: 'POST',
        url: 'categories',
        data
    })
}

// 根据id查询分类
export const selectCategoriesAPI = (id) => {
    return request({
        method: 'GET',
        url: `categories/${id}`
    })
}

// 编辑商品分类
export const editCategoriesAPI = (id, name) => {
    return request({
        method: 'PUT',
        url: `categories/${id}`,
        data: {
            cat_name: name
        }
    })
}

// 删除商品分类
export const delCategoriesAPI = (id) => {
    return request({
        method: 'DELETE',
        url: `categories/${id}`
    })
}

// 获取参数列表
export const getparameterListAPI = (id, sel) => {
    return request({
        method: 'GET',
        url: `categories/${id}/attributes`,
        params: {
            sel
        }
    })
}

// 添加参数
/**| 参数名    | 参数说明                                   | 备注                  |
| --------- | ------------------------------------------ | --------------------- |
| :id       | 分类 ID                                    | 不能为空`携带在url中` |
| attr_name | 参数名称                                   | 不能为空              |
| attr_sel  | [only,many]                                | 不能为空              |
| attr_vals | 如果是 many 就需要填写值的选项，以逗号分隔 | 【可选参数】          | */
export const addparameterAPI = (id,data) =>{
    return request({
        method:'POST',
        url:`categories/${id}/attributes`,
        data
    })
}

// 编辑提交参数
export const editparameterAPI = (id,attrId,data)=>{
    return request({
        method:'PUT',
        url:`categories/${id}/attributes/${attrId}`,
        data
    })
}

// 删除参数
export const delparameterAPI = (id,attrId) =>{
    return request({
        method:'DELETE',
        url:`categories/${id}/attributes/${attrId}`
    })
}